// Misperception susceptibility
// Outcome: AUC
// Uses outreg2 package
// Used three datasets: PanelPublic.dta, AUC.dta, and tfslantPublic.dta

use "PanelPublic.dta", clear

set scheme uncluttered

egen completeWs=rownonmiss(starttime_W1 starttime_W2 starttime_W3 starttime_W4 starttime_W5 ///
	starttime_W6 starttime_W7 starttime_W8 starttime_W9 starttime_W10 starttime_W11 starttime_W12), strok
tab completeWs

// Missing values
recode gender educ polid_W1 socid_W1 ecoid_W1 pid3 Feel1_W1-TIP4_W1 (8/9=.)

// Demographics
recode gender (1=1) (2=0), gen(maled)
alpha polid_W1 ecoid_W1 socid_W1
egen polid = rowmean(polid_W1 ecoid_W1 socid_W1 )
sum polid
gen age = 2019-birthyr

// Epistemic beliefs
alpha (Feel1_W1-Feel4_W1)
alpha (Evid1_W1-Evid4_W1)
alpha (TIP1_W1-TIP4_W1)
egen feel=rowmean(Feel1_W1-Feel4_W1)
lab var feel "Faith in Intuition for Facts"
egen evid=rowmean(Evid1_W1-Evid4_W1)
lab var evid "Need for Evidence"
egen TIP=rowmean(TIP1_W1-TIP4_W1)
lab var TIP "Truth is Political"
sum feel evid TIP

// Convert to long format
gen id = _n
reshape long starttime_W endtime_W ///
	F1e_W F2e_W F3e_W F4e_W F5e_W F6e_W F7e_W F8e_W F9e_W F10e_W ///
	T1e_W T2e_W T3e_W T4e_W T5e_W T6e_W T7e_W T8e_W T9e_W T10e_W ///
	F1b_W F2b_W F3b_W F4b_W F5b_W F6b_W F7b_W F8b_W F9b_W F10b_W ///
	T1b_W T2b_W T3b_W T4b_W T5b_W T6b_W T7b_W T8b_W T9b_W T10b_W ///
	F1bn_W F2bn_W F3bn_W F4bn_W F5bn_W F6bn_W F7bn_W F8bn_W F9bn_W F10bn_W ///
	T1bn_W T2bn_W T3bn_W T4bn_W T5bn_W T6bn_W T7bn_W T8bn_W T9bn_W T10bn_W ///
	, i(id) j(wave)

// Omit missing waves
drop if starttime_ == .
	
lab def w 1 "W1" 2 "W2" 3 "W3" 4 "W4" 5 "W5" 6 "W6" 7 "W7" 8 "W8" 9 "W9" ///
	10 "W10" 11 "W11" 12 "W12"
lab val wave w
xtset id wave, generic

// Adding AUC & statement slant data
// Note: AUC can be recreated using panelPublic.dta and prepAUCpublic.do
// Note: id2 is sequential (1-10,367) when sorted by wave (1-12) and id (1-1204)
gsort +id +wave
gen id2 = _n
merge 1:1 id2 using "AUC.dta"
drop _merge bias

merge 1:1 id2 using "tfSlantPublic.dta"
drop _merge

// Export a copy for density plots in R
export delimited using "panelAUC.csv", replace nolabel

// Table S5
xtsum polid
xtsum AUC
xtsum age maled educ 
xtsum feel evid TIP 
xtsum conT conF proT proF

//
// Sensitivity (AUC)
//

// Fig. 3B
graph box proT conT proF conF if pid3==1, ///
	box(1, color(green*2) lwidth(vthin)) ///
	box(2, color(green*1.5) lwidth(thick)) ///
	box(3, color(red*2) lwidth(vthin)) ///
	box(4, color(red*1.5) lwidth(thick)) ///
	ytitle("Proportion of statements in each wave") graphregion(margin(b+5)) ///
	text(1 -18 "{bf:B}", place(c)) ///
	text(-.08 15 "D+/R-", place(c) size(small)) ///
	text(-.08 39 "D-/R+", place(c) size(small)) ///
	text(-.13 27 "{bf:Truths}", place(c) size(small)) ///
	text(-.08 64 "D+/R-", place(c) size(small)) ///
	text(-.08 90 "D-/R+", place(c) size(small)) ///
	text(-.13 77 "{bf:Falsehoods}", place(c) size(small)) ///
	xsize(4.5) ysize(4.5) name(fig3b, replace) 
	
// *** Random effects regression models ***

// Table S6
xtreg AUC age maled educ feel evid TIP polid ///
	i.wave, re level(95)

// Fig. 2A
margins, at(polid=(1(1)7))
marginsplot, ///
	ytitle("Predicted sensitivity (AUC)") ylabel(.5(.1)1) ///
	yline(.5, lpattern(dash) lc(red)) ///
	xlabel(, labsize(small)) ///
	xtitle("Political ideology (conservatism high)", size(medium)) ///
	ciopts(recast(rarea)) ///
	xsize(4.4) ysize(4.5) ///
	text(1.01 .2 "{bf:A}", place(s)) ///
	title("") ///
	name(fig2a, replace)
outreg2 using "S6", dec(3) alpha(0.001, 0.01, 0.05) word replace 	
	
// Table S8
xtreg AUC age maled educ feel evid TIP ///
	conT conF proT proF polid, re level(95)
outreg2 using "S8", dec(3) alpha(0.001, 0.01, 0.05) word replace 	
	
// *** Fixed effects regression models ***

// Table S10
xtreg AUC conT conF proT proF ///
	c.conT#c.polid c.conF#c.polid c.proT#c.polid c.proF#c.polid,  ///
	fe level(95)
outreg2 using "S10", dec(3) alpha(0.001, 0.01, 0.05) word replace 	

// Fig. 4A
margins, at(conT=(.1(.1).9) polid=(1 7))
marginsplot, ///
	ytitle("Predicted sensitivity (AUC)") ylabel(.5(.1)1) ///
	xlabel(0(.2)1, labsize(small)) text(1 .1 "{bf:A}", place(s)) ///
	xtitle("% truths that harm in-group", size(large)) ///
	yline(.5, lpattern(dash) lc(red)) ///
	plot1opts(lcolor(blue) mcolor(blue)) plot2opts(lcolor(red) mcolor(red)) ///
	ci1opts(lcolor(blue) recast(rarea)) ci2opts(lcolor(red) recast(rarea)) ///
	legend(order(3 "Very liberal" 4 "Very conservative")) ///
	xsize(4.4) ysize(4.5) ///
	title("") ///
	name(Fig4a, replace)
	
// Fig. 4B
margins, at(conF=(.1(.1).9) polid=(1 7))
marginsplot, ///
	ytitle("") ylabel(.5(.1)1) ///
	xlabel(0(.2)1, labsize(small)) text(1 .1 "{bf:B}", place(s)) ///
	xtitle("% falsehoods that harm in-group", size(large)) ///
	yline(.5, lpattern(dash) lc(red)) ///
	plot1opts(lcolor(blue) mcolor(blue)) plot2opts(lcolor(red) mcolor(red)) ///
	ci1opts(lcolor(blue) recast(rarea)) ci2opts(lcolor(red) recast(rarea)) ///
	legend(order(3 "Very liberal" 4 "Very conservative")) ///
	xsize(4.4) ysize(4.5) ///
	title("") ///
	name(Fig4b, replace)
	
// Fig. 4C
margins, at(proT=(.1(.1).9) polid=(1 7))
marginsplot, ///
	ytitle("Predicted sensitivity (AUC)") ylabel(.5(.1)1) ///
	xlabel(0(.2)1, labsize(small)) text(1 .1 "{bf:C}", place(s)) ///
	xtitle("% truths that benefit in-group", size(large)) ///
	yline(.5, lpattern(dash) lc(red)) ///
	plot1opts(lcolor(blue) mcolor(blue)) plot2opts(lcolor(red) mcolor(red)) ///
	ci1opts(lcolor(blue) recast(rarea)) ci2opts(lcolor(red) recast(rarea)) ///
	legend(order(3 "Very liberal" 4 "Very conservative")) ///
	xsize(4.4) ysize(4.5) ///
	title("") ///
	name(Fig4c, replace)

// Fig. 4D
margins, at(proF=(.1(.1).9) polid=(1 7))
marginsplot, ///
	ytitle("") ylabel(.5(.1)1) ///
	xlabel(0(.2)1, labsize(small)) text(1 .1 "{bf:D}", place(s)) ///
	xtitle("% falsehoods that benefit in-group", size(large)) ///
	yline(.5, lpattern(dash) lc(red)) ///
	plot1opts(lcolor(blue) mcolor(blue)) plot2opts(lcolor(red) mcolor(red)) ///
	ci1opts(lcolor(blue) recast(rarea)) ci2opts(lcolor(red) recast(rarea)) ///
	legend(order(3 "Very liberal" 4 "Very conservative")) ///
	xsize(4.4) ysize(4.5) ///
	title("") ///
	name(Fig4d, replace)

// Fig. 4 (combined)
graph combine Fig4a Fig4b Fig4c Fig4d, row(2) ycommon ///
	name(Fig4,replace)

***
*** REPLICATE WITH Ps WHO COMPLETE 6+ or 12 waves
***

preserve
drop if completeWs<6

xtreg AUC age maled educ feel evid TIP polid ///
	i.wave, re level(95)

outreg2 using "S12", dec(3) alpha(0.001, 0.01, 0.05) word replace 	

xtreg AUC age maled educ feel evid TIP ///
	conT conF proT proF polid, re level(95)

outreg2 using "S14", dec(3) alpha(0.001, 0.01, 0.05) word replace 	

xtreg AUC conT conF proT proF ///
	c.conT#c.polid c.conF#c.polid c.proT#c.polid c.proF#c.polid,  ///
	fe level(95)

outreg2 using "S16", dec(3) alpha(0.001, 0.01, 0.05) word replace 	
	
restore
	
preserve
drop if completeWs!=12

xtreg AUC age maled educ feel evid TIP polid ///
	i.wave, re level(95)

outreg2 using "S18", dec(3) alpha(0.001, 0.01, 0.05) word replace 	

xtreg AUC age maled educ feel evid TIP ///
	conT conF proT proF polid, re level(95)

outreg2 using "S20", dec(3) alpha(0.001, 0.01, 0.05) word replace 	

xtreg AUC conT conF proT proF ///
	c.conT#c.polid c.conF#c.polid c.proT#c.polid c.proF#c.polid,  ///
	fe level(95)

outreg2 using "S22", dec(3) alpha(0.001, 0.01, 0.05) word replace 	
	
restore
